home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / c2p_mono.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  8KB  |  251 lines

  1. /* :ts=4                            c2p_mono.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #include <proto/graphics.h>
  23. #include <proto/exec.h>
  24. #include <proto/intuition.h>
  25.  
  26. #include "cp4_ver.h"
  27.  
  28. #define C2P_VERSION        "1"
  29. #define C2P_REVISION    "3"
  30. #define C2P_AUTHOR        "gega <Gáti Gergely>"
  31. #define C2P_NAME        "Mono"
  32. #define C2P_BUFFERING    3
  33. #define C2P_DATE        DATE
  34. #define C2P_LOCALIZE
  35.  
  36. #include "c2p_module.c"
  37.  
  38. extern void REGARGS convfullasm(    REG(a0,void *chunkyaddr),
  39.                                     REG(a1,void *planaraddr) );
  40. extern void REGARGS convdeltaasm(    REG(a0,void *chunkyaddr),
  41.                                     REG(d0,void *delta),
  42.                                     REG(a1,void *planaraddr) );
  43.  
  44. struct GfxBase *GfxBase=NULL;
  45. struct IntuitionBase *IntuitionBase=NULL;
  46. static int winsleeped=0;
  47. static struct Requester InvisibleRequester;
  48. static ULONG Palette[]={
  49.     2<<16,
  50.     0x00000000,0x00000000,0x00000000,
  51.     0xffffffff,0xffffffff,0xffffffff,
  52.     0L
  53. };
  54. static struct BitMap *bmap[3];
  55. static unsigned char *planars[3];
  56. static struct Screen *scr=NULL;
  57. static struct Window *win=NULL;
  58. static UWORD *nopointer=NULL;
  59. static struct ScreenBuffer *scrb[3];
  60.     int bmx;
  61. static unsigned char *lineskip;
  62. /*
  63.  * conversion table, 00/ff
  64.  */
  65. static unsigned char table[]={
  66. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 1
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  71. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  72. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  73. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, // 1
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 2
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  79. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  80. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  81. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF  // 2
  82. };
  83. unsigned char *tablep=table;
  84.  
  85. #define MSG_INFO 0
  86. #define MSG_NOSCRMODE 1
  87. #define MSG_NOGFX 2
  88. #define MSG_NOINTUI 3
  89. #define MSG_NOSCR 4
  90. #define MSG_NOWIN 5
  91. #define MSG_NOMEM 6
  92.  
  93. static char *defstr[]={
  94.     "Monochrome driver on an Intuition Screen.",
  95.     "No ScreenMode Specified",
  96.     "Can't open graphics.library V39",
  97.     "Can't open intuition.library V37",
  98.     "Can't open Screen",
  99.     "Can't open Window",
  100.     "Not enough memory",
  101.     NULL
  102. };
  103.  
  104.  
  105. char *SAVEDS minfo(void) {
  106. static char in[1024];
  107.     char *s;
  108.     c2p_OpenCatalog(defstr);
  109.     s=STR(MSG_INFO);
  110.     c2p_strncpy(in,s,1023);
  111.     c2p_CloseCatalog();
  112.     return(in);
  113. }
  114.  
  115. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab) {
  116.     ULONG bf=BMF_CLEAR|BMF_DISPLAYABLE;
  117.  
  118.     c2p_OpenCatalog(defstr);
  119.  
  120.     lineskip=linedeltatab;
  121.     if(scrmode==~0) return(STR(MSG_NOSCRMODE));
  122.  
  123.     if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39))==NULL) return(STR(MSG_NOGFX));
  124.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37))) return(STR(MSG_NOINTUI));
  125.  
  126.     /* Allocate mem for nopointer
  127.      */
  128.     if(NULL==(nopointer=AllocVec(24,MEMF_CHIP|MEMF_CLEAR))) return(STR(MSG_NOMEM));
  129.  
  130.     /* Allocate bitmaps
  131.      */
  132.     bmap[0]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  133.     bmap[1]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  134.     bmap[2]=AllocBitMap(SCRWIDTH,SCRHEIGHT,1,bf,NULL);
  135.     if(bmap[0]==NULL||bmap[1]==NULL||bmap[2]==NULL) return(STR(MSG_NOMEM));
  136.     bmx=GetBitMapAttr(bmap[0],BMA_WIDTH)/8;
  137.     planars[0]=(unsigned char *)bmap[0]->Planes[0];
  138.     planars[1]=(unsigned char *)bmap[1]->Planes[0];
  139.     planars[2]=(unsigned char *)bmap[2]->Planes[0];
  140.  
  141.     /* Open Screen
  142.      */
  143.     if(NULL==(scr=OpenScreenTags(NULL,
  144.                 SA_DisplayID, scrmode,
  145.                 SA_Depth, 1,
  146.                 SA_ShowTitle,FALSE,
  147.                 SA_Quiet, TRUE,
  148.                    SA_Width,SCRWIDTH,
  149.                    SA_Height,SCRHEIGHT,
  150.                    SA_BitMap, (ULONG)bmap[0],
  151.                    SA_Behind, TRUE,
  152.                    SA_Colors32, (ULONG)Palette,
  153.                 SA_Overscan, overscan,
  154.                 TAG_DONE,0L )))
  155.         return(STR(MSG_NOSCR));
  156.     vec.c2p_Scr=scr;
  157.  
  158.     /* Open window
  159.      */
  160.     if((win=(struct Window *)OpenWindowTags(NULL,
  161.                 WA_NoCareRefresh, TRUE,
  162.                 WA_Activate, TRUE,
  163.                 WA_Borderless, TRUE,
  164.                 WA_Backdrop, TRUE,
  165.                 WA_CustomScreen, (ULONG)scr,
  166.                 WA_RMBTrap, TRUE,
  167.                 WA_RptQueue, 25,
  168.                 TAG_DONE,0L ))==NULL)
  169.         return(STR(MSG_NOWIN));
  170.     vec.c2p_Win=win;
  171.     winsleeped=0;
  172.  
  173.     /* set nopointer
  174.      */
  175.     SetPointer(win,nopointer,1,16,0,0);
  176.  
  177.     /* Allocate screen buffers
  178.      */
  179.     scrb[0]=AllocScreenBuffer(scr,bmap[0],NULL);
  180.     scrb[1]=AllocScreenBuffer(scr,bmap[1],NULL);
  181.     scrb[2]=AllocScreenBuffer(scr,bmap[2],NULL);
  182.     if(scrb[0]==NULL||scrb[1]==NULL||scrb[2]==NULL) return(STR(MSG_NOMEM));
  183.     scrb[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  184.     scrb[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  185.     scrb[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  186.     scrb[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  187.     scrb[2]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  188.     scrb[2]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  189.     return(NULL);
  190. } // minit
  191.  
  192.  
  193. void SAVEDS mfree(void) {
  194.     mawake();
  195.     if(GfxBase) WaitTOF();
  196.     if(scrb[0]) { FreeScreenBuffer(scr,scrb[0]); scrb[0]=NULL; }
  197.     if(scrb[1]) { FreeScreenBuffer(scr,scrb[1]); scrb[1]=NULL; }
  198.     if(scrb[2]) { FreeScreenBuffer(scr,scrb[2]); scrb[2]=NULL; }
  199.     if(win) ClearPointer(win);
  200.     if(nopointer) { FreeVec(nopointer); nopointer=NULL; }
  201.     if(win) { CloseWindow(win); win=NULL; }
  202.     vec.c2p_Win=NULL;
  203.     if(scr) { CloseScreen(scr); scr=NULL; }
  204.     vec.c2p_Scr=NULL;
  205.     if(bmap[0]) { FreeBitMap(bmap[0]); bmap[0]=NULL; }
  206.     if(bmap[1]) { FreeBitMap(bmap[1]); bmap[1]=NULL; }
  207.     if(bmap[2]) { FreeBitMap(bmap[2]); bmap[2]=NULL; }
  208.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  209.     if(IntuitionBase) { CloseLibrary((struct Library *)IntuitionBase); IntuitionBase=NULL; }
  210.     c2p_CloseCatalog();
  211.     return;
  212. } // free
  213.  
  214.  
  215. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen) {
  216.     convdeltaasm(chunky,delta,planars[numscreen]);
  217.     ChangeScreenBuffer(scr,scrb[numscreen]);
  218.     return(RET_OK);
  219. } // do
  220.  
  221. int SAVEDS mdofull(unsigned char *chunky,int numscreen) {
  222.     convfullasm(chunky,planars[numscreen]);
  223.     ChangeScreenBuffer(scr,scrb[numscreen]);
  224.     return(RET_OK);
  225. } // dofull
  226.  
  227. int SAVEDS mdont(void) {
  228.     return(RET_OK);
  229. } // dont
  230.  
  231. void SAVEDS msleep(void) {
  232.     if(win) {
  233.         InitRequester(&InvisibleRequester);
  234.         Request(&InvisibleRequester,win);
  235.         SetWindowPointer(win,WA_BusyPointer,TRUE,TAG_DONE);
  236.         winsleeped=1;
  237.     }
  238. }
  239.  
  240.  
  241. void SAVEDS mawake(void) {
  242.     if(winsleeped) {
  243.         if(win) {
  244.             EndRequest(&InvisibleRequester,win);
  245.             SetWindowPointerA(win,NULL);
  246.             SetPointer(win,nopointer,1,16,0,0);
  247.             winsleeped=0;
  248.         }
  249.     }
  250. }
  251.